{% extends "service_log/sl_base.html" %}

{% load i18n %}
{% load widget_tweaks %}
{% load qa_tags %}
{% load qatrack_tags %}
{% load attach_tags %}
{% load comments %}
{% load static %}

{% block head_title %}
  {% if form.instance.id %}
    {% blocktrans with service_event_id=form.instance.id %}
      Edit Service Event #{{ service_event_id }}
    {% endblocktrans %}
  {% else %}
    {% trans "Enter New Service Event" %}
  {% endif %}
{% endblock %}

{% block extra_css %}
    {{ block.super }}
    <link href="{% static "select2/css/select2.min.css" %}?v={{ VERSION }}" rel="stylesheet">
    <link href="{% static "qatrack_core/css/tables.css" %}?v={{ VERSION }}" rel="stylesheet">
    <link href="{% static "qatrack_core/css/custom-select2.css" %}?v={{ VERSION }}" rel="stylesheet">
    <link href="{% static "flatpickr/css/flatpickr.css" %}?v={{ VERSION }}" rel="stylesheet">
    <link href="{% static "qatrack_core/css/flatpickr-custom.css" %}?v={{ VERSION }}" rel="stylesheet">
{% endblock extra_css %}

{% block extra_js %}
  <script type="text/javascript">
      var status_colours_dict = {{ status_tag_colours|safe }};
      var se_statuses = {{ se_statuses|safe }};
      var se_types_review = {{ se_types_review|safe }};
      var se_id = {% if form.instance.id %}{{ form.instance.id }}{% else %}false{% endif %};
      var from_se_schedule  = {% if se_schedule %}{{ se_schedule.id }}{% else %}false{% endif %};
  </script>
{% endblock extra_js %}

{% block require_javascript %}
  require(['sl_se']);
{% endblock require_javascript %}

{% block body %}

  <form id="service-event-form" action="" method="post" novalidate enctype="multipart/form-data">
    {% csrf_token %}
    <div class="max-width-lg">
      <div id="submit_cover" class="max-width-lg" style="display: none;">

        <div class="loading-modal-center">
          <div>
            <span class="loading-logo">QAT</span>
            <i class="fa fa-fw fa-plus fa-spin fa-2x info"></i>
          </div>
          <div>
            <b>{% trans "Submitting Service Log" %}...</b>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-md-12">
          <h3 class="no-margin-top">
            {% if form.instance.id %}
              {% blocktrans with service_event_id=form.instance.id %}
                Edit Service Event {{ service_event_id }}
              {% endblocktrans %}
            {% elif se_template %}
              {% blocktrans with template_name=se_template.name %}
                Create Service Event from template "{{ template_name }}"
              {% endblocktrans %}
            {% else %}
              {% trans "Create Service Event" %}
            {% endif %}
          </h3>
        </div>
      </div>
      <div class="row">
        <div class="col-md-4">
          {% for field in form.fieldsets.service_status %}
            <div class="form-horizontal">
              <div class="form-group {% if field.errors %}has-error{% endif %}">
                <label for="{{ field.id_for_label }}" class="col-sm-5">{{ field.label }}</label>
                <div class="col-sm-7">
                  {{ field }}
                </div>
                {% for e in field.errors %}
                  <div class="col-sm-12 help-block text-center">{{ e }}</div>
                {% endfor %}
              </div>
            </div>
          {% endfor %}
        </div>
        <div class="col-md-7">
          {% if form.instance.id %}
            <div class="col-sm-4">
              <dl>
                <dt>{% trans "Created" %}:</dt>
                <dd>
                  <div>{{ form.instance.datetime_created }}</div>
                  <div>by {{ form.instance.user_created_by|get_user_name }}</div>
                </dd>
              </dl>
            </div>
            {% if form.instance.datetime_modified %}
              <div class="col-sm-4">
                <dl>
                  <dt>{% trans "Modified" %}:</dt>
                  <dd>
                    <div>{{ form.instance.datetime_modified }}</div>
                    <div>
                      {% blocktrans with username=form.instance.user_modified_by|get_user_name %}
                        by {{ username }}
                      {% endblocktrans %}
                    </div>
                  </dd>
                </dl>
              </div>
            {% endif %}
            {% if form.instance.datetime_status_changed %}
              <div class="col-sm-4">
                <dl>
                  <dt>{% trans "Status Changed" %}:</dt>
                  <dd>
                    <div>{{ form.instance.datetime_status_changed }}</div>
                    <div>
                      {% if form.instance.user_status_changed_by %}
                        {% blocktrans with username=form.instance.user_status_changed_by|get_user_name %}
                          by {{ username }}
                        {% endblocktrans %}
                      {% else %}
                        {% trans "System" %}
                      {% endif %}
                    </div>
                  </dd>
                </dl>
              </div>
            {% endif %}
          {% endif %}
        </div>
        <div class="col-sm-1">
          <button class="btn btn-flat btn-primary service-save pull-right">{% trans "Save" %}</button>
        </div>
      </div>

      <div class="row">
        <div class="col-md-12">
          <div class="box">
            <div class="box-header">

            </div>
            <div class="box-body">
              <div class="row" style="display: none;">

                {% for field in form.fieldsets.hidden_fields %}
                  {{ field }}
                  {% if field.errors %}
                    {{ field.errors }}
                  {% endif %}
                {% endfor %}
                <input id="instance-id" type="hidden" readonly="readonly"
                       value="{% if form.instance.pk %}{{ form.instance.pk }}{% endif %}">
              </div>
              <div class="row">
                <div id="required-fields" class="col-md-6 form-horizontal">

                  {% for field in form.fieldsets.left_fields %}
                    <div class="form-group {% if field.errors %}has-error{% endif %}" title="{{ field.help_text }}">
                      <label for="{{ field.id_for_label }}" class="col-sm-4">
                        {{ field.required }}
                        {{ field.label }}{% if field.field.required %} *{% endif %}
                      </label>
                      <div class="col-sm-8">
                        {{ field }}
                        {% if field.help_text %}
                          <div class="help-block margin-0">{{ field.help_text }}</div>
                        {% endif %}
                      </div>
                      {% for e in field.errors %}
                        <div class="col-sm-4"></div>
                        <div class="col-sm-8 help-block text-center">{{ e }}</div>
                      {% endfor %}
                    </div>
                  {% endfor %}
                </div>

                <div id="optional-fields" class="col-md-6 form-horizontal">

                  {% for field in form.fieldsets.right_fields %}
                    <div class="form-group {% if field.errors %}has-error{% endif %}" title="{{ field.help_text }}">
                      <label for="{{ field.id_for_label }}" class="col-sm-4">
                        {{ field.label }}{% if field.field.required %} *{% endif %}
                      </label>

                      <div class="col-sm-8">
                        {% if field.html_name == 'service_event_template' and perms.service_log.add_serviceeventtemplate and not se_template %}
                          <div class="input-group">
                            {{ field }}
                            <div class="input-group-btn">
                              <div class="btn btn-flat btn-sm btn-default se-template-btn"
                                   title="{% trans "Create service event template with currently selected values for Unit, Service Area, Service Type, Review Required, Descriptions, and any Return to Service TestLists" %}"
                                   data-toggle="modal"
                                   >{% trans "Create" %}
                              </div>
                            </div>
                          </div>
                        {% else %}
                          {{ field }}
                        {% endif %}
                        {% if field.help_text %}
                          <div class="help-block margin-0">{{ field.help_text }}</div>
                        {% endif %}
                      </div>
                      {% for e in field.errors %}
                        <div class="col-sm-4"></div>
                        <div class="col-sm-8 help-block text-center">{{ e }}</div>
                      {% endfor %}
                    </div>
                  {% endfor %}
                </div>
              </div>
              <div class="row">
                {% for field in form.fieldsets.problem_and_safety %}
                  <div class="col-sm-6 form-horizontal">
                    <div class="form-group {% if field.errors %}has-error{% endif %}" title="{{ field.help_text }}">
                      <div class="col-sm-12">
                        <label for="{{ field.id_for_label }}" class="">
                          <span>{{ field.label }}{% if field.field.required %} *{% endif %}</span>
                          {% if field.help_text %} -
                            <span class="help-block margin-bottom-0 display-inline-block">{{ field.help_text }}</span>{% endif %}
                        </label>
                        {{ field }}
                        {% for e in field.errors %}
                          <div class="col-sm-12 help-block text-center">{{ e }}</div>
                        {% endfor %}
                      </div>
                    </div>
                  </div>
                {% endfor %}
              </div>
              <div class="row">
                <div class="col-sm-12 form-horizontal">
                  {% for field in form.fieldsets.work_description %}
                    <div class="form-group {% if field.errors %}has-error{% endif %}" title="{{ field.help_text }}">
                      <div class="col-sm-12">
                        <label for="{{ field.id_for_label }}" class="">
                          <span>{{ field.label }}{% if field.field.required %} *{% endif %}</span>
                          {% if field.help_text %} -
                            <span class="help-block margin-bottom-0 display-inline-block">{{ field.help_text }}</span>{% endif %}
                        </label>
                        {{ field }}
                        {% for e in field.errors %}
                          <div class="col-sm-12 help-block text-center">{{ e }}</div>
                        {% endfor %}
                      </div>
                    </div>
                  {% endfor %}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="row">
        <div class="col-md-4">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">
                <i class="fa fa-clock-o fa-fw" aria-hidden="true"></i>
                {% trans "Involved Parties and Durations" %}
              </h3>
            </div>
            <div class="box-body">
              <div class="subheading-divider">{% trans "Service Event Durations" %}</div>
              <div class="row margin-bottom-15">
                <div class="col-md-12 form-horizontal">
                  {% for field in form.fieldsets.time_fields %}
                    <div class="form-group margin-bottom-5{% if field.errors %}has-error{% endif %}"
                         title="{{ field.help_text }}">
                      <label class="col-md-6" for="{{ field.id_for_label }}">
                        <span>{{ field.label }}</span>
                        - <span class="help-block margin-bottom-0 display-inline-block">{% trans "(hh:mm)" %}</span>
                      </label>
                      <div class="col-md-6">
                        {{ field }}
                      </div>
                      {% if field.errors %}
                        <div class="col-md-6"></div>
                        <div class="col-md-6">{{ field.errors }}</div>
                      {% endif %}
                    </div>
                  {% endfor %}
                </div>
              </div>

              {% if form.fieldsets.g_link_fields.boundfields|length > 0 %}
              <div class="subheading-divider">{% trans "Group Members Involved" %}</div>
                <div class="row margin-bottom-15">
                  <div id="g-link-fields" class="col-md-12 form-horizontal">
                    {% for field in form.fieldsets.g_link_fields %}
                      <div class="form-group margin-bottom-5{% if field.errors %} has-error{% endif %}"
                           title="{{ field.field.title }}">
                        <label for="{{ field.id_for_label }}"
                               class="col-sm-6{% if field.field.required %} required{% endif %}">
                          <div>{{ field.label }}{% if field.field.required %} *{% endif %}</div>
                          {% if field.help_text %}
                            <div class="help-block margin-0 display-inline-block">{{ field.help_text }}</div>{% endif %}
                        </label>
                        <div class="col-sm-6">
                          {{ field }}
                        </div>
                        {% for e in field.errors %}
                          <div class="col-sm-6"></div>
                          <div class="col-sm-6 help-block text-center">{{ e }}</div>
                        {% endfor %}
                      </div>
                    {% endfor %}
                  </div>
                </div>
              {% endif %}
              <div class="subheading-divider">{% trans "User and Third Party Work Durations" %}</div>
              <div class="row">
                <div class="col-md-12">
                  <table class="table table-hover table-condensed">
                    <thead>
                    {{ hours_formset.management_form }}
                    <tr>
                      <th>{% trans "User or Third Party" %}</th>
                      <th class="max-width-75">{% trans "Time (hh:mm)" %}</th>
                      <th class="max-width-50">{% trans "Delete" %}</th>
                    </tr>
                    </thead>

                    <tbody id="hours-tbody">

                    {% for h_form in hours_formset.forms %}
                      {% if h_form.instance.pk or not h_form.DELETE.widget.attrs.checked %}
                        <tr id="{{ h_form.prefix }}" class="hours-row">
                          {{ h_form.id }}
                          <td class="form-group{% if h_form.user_or_thirdparty.errors %} has-error{% endif %}">
                            {{ h_form.user_or_thirdparty }}
                            {% for e in h_form.user_or_thirdparty.errors %}
                              <div class="help-block">{{ e }}</div>
                            {% endfor %}

                            {% for e in h_form.non_field_errors %}
                              <div class="help-block">{{ e }}</div>
                            {% endfor %}
                          </td>
                          <td class="{% if h_form.time.errors %} has-error{% endif %}"
                              title="{{ h_form.time.help_text }}">
                            {{ h_form.time }}
                            {% for e in h_form.time.errors %}
                              <div class="help-block">{{ e }}</div>
                            {% endfor %}
                          </td>
                          <td align="center">
                            {% if h_form.instance.pk %}{{ h_form.DELETE }}{% endif %}
                          </td>
                        </tr>
                      {% endif %}
                    {% endfor %}

                    </tbody>

                    <tfoot>
                    <tr>
                      <td colspan="3">
                        <div id="add-hours" class="btn btn-sm btn-flat btn-default pull-right"
                            title="{% trans "Add another hours object." %}"
                        >
                          {% trans "Add" %}
                        </div>
                      </td>
                    </tr>
                    </tfoot>

                  </table>
                </div>
              </div>

            </div>
          </div>
        </div>

        <div class="col-md-8">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">
                <i class="fa fa-stack fa-fw">
                  <i class="fa fa-pencil-square-o fa-stack-custom-main"></i>
                  <i class="fa fa-share fa-rotate-180 fa-stack-custom-sub lower-extra-left info"></i>
                </i>
                {% trans "Return To Service QC" %}
              </h3>
            </div>
            <div class="box-body">
              {{ rtsqa_formset.management_form }}
              {% if perms.service_log.add_returntoserviceqa or rtsqa_formset.forms|length > 0 %}
              <div class="subheading-divider">{% trans "Return To Service QC Required" %}</div>
                <div class="row">
                  <div class="col-md-12">

                    <table class="table table-hover table-condensed">
                      <thead>
                      <tr>
                        <th style="min-width: 200px;">{% trans "Test List" %}</th>
                        <th>{% trans "Completed" %}</th>
                        <th>{% trans "Pass/Fail" %}</th>
                        <th>{% trans "Review Status" %}</th>
                        <th></th>
                        <th>{% if perms.service_log.delete_returntoserviceqa %}{% trans "Delete" %}{% endif %}</th>
                      </tr>
                      </thead>

                      <tbody id="rtsqa-tbody">

                      {% for f_form in rtsqa_formset.forms %}
                        <tr id="{{ f_form.prefix }}" class="rtsqa-row">
                          {{ f_form.id }}
                          {{ f_form.test_list_instance }}
                          {{ f_form.all_reviewed }}
                          <td class="form-group{% if f_form.unit_test_collection.errors %} has-error{% endif %}">
                            {{ f_form.unit_test_collection }}
                            {% for e in f_form.unit_test_collection.errors %}
                              <div class="help-block">{{ e }}</div>
                            {% endfor %}
                          </td>
                          <td id="work-completed-{{ f_form.prefix }}"></td>
                          <td id="pass-fail-{{ f_form.prefix }}"></td>
                          <td id="review-{{ f_form.prefix }}"></td>
                          <td id="utc-actions-{{ f_form.prefix }}"></td>
                          <td align="center">{% if perms.service_log.delete_returntoserviceqa and f_form.instance.pk %}
                            {{ f_form.DELETE }}{% endif %}</td>
                        </tr>
                      {% endfor %}

                      </tbody>

                      {% if perms.service_log.add_returntoserviceqa %}
                        <tfoot>
                        <tr>
                          <td colspan="5">
                            <div id="add-rtsqa" class="btn btn-sm btn-flat btn-default pull-right"
                                title="{% trans "Add another RTS QC object." %}">
                              {% trans "Add" %}
                            </div>
                          </td>
                        </tr>
                        </tfoot>
                      {% endif %}

                    </table>
                  </div>
                </div>
              {% endif %}


              <div class="subheading-divider">{% trans "Comments" %}</div>
              {% if form.instance.pk %}
                <div class="row">
                  <div class="col-md-12">
                    {% render_comment_list for form.instance %}
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-12">
                    {% get_comment_form for form.instance as c_form %}

                    <div id="comment-form">
                      {% csrf_token %}
                      <input id="id_name" maxlength="50" name="name" type="hidden" required=""
                             value="{{ user.username }}">
                      {{ c_form.object_pk }}
                      {{ c_form.content_type }}
                      {{ c_form.security_hash }}
                      {{ c_form.timestamp }}
                      <textarea cols="40" id="id_comment" maxlength="3000" name="comment" rows="2" required=""
                          placeholder="{% trans "Add comment" %}" class="margin-bottom-20 form-control autosize"></textarea>
                    </div>
                    <div class="row">
                      <div class="col-md-12">
                        <div id="post-comment" class="btn btn-flat btn-info btn-sm pull-right disabled">
                          {% trans "Post Comment" %}
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              {% else %}
                {% with form.qafollowup_comments as field %}
                  <div class="form-group {% if field.errors %}has-error{% endif %}" title="{{ field.help_text }}">
                    <div class="col-sm-12">
                      <label for="{{ field.id_for_label }}" class="">
                        <span>{{ field.label }}</span>
                        {% if field.help_text %} -
                          <span class="help-block margin-bottom-0 display-inline-block">{{ field.help_text }}</span>{% endif %}
                      </label>
                      {{ field }}
                      {% for e in field.errors %}
                        <div class="col-sm-12 help-block text-center">{{ e }}</div>
                      {% endfor %}
                    </div>
                  </div>
                {% endwith %}
              {% endif %}


            </div>
          </div>
        </div>
      </div>

      <div class="row">
        <div class="col-md-4">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title{% if form.se_attachments.errors %} has-error{% endif %}">
                <i class="fa fa-cog fa-fw" aria-hidden="true"></i>
                {% trans "Attachments" %}
              </h3>
            </div>
            <div class="box-body">
              <div class="row">
                <div class="col-sm-12">
                  <table id="attach-table" class="table table-responsive table-condensed">
                    <thead>
                    <tr>
                      <th>{% trans "Filename" %}</th>
                      <th>{% trans "Delete" %}</th>
                    </tr>
                    </thead>
                    <tbody>
                    {{ form.se_attachments_delete_ids }}
                    {% if form.instance.id %}
                      {% for attach in form.instance.attachment_set.all %}
                        <tr>
                          <td><i class="fa fa-paperclip fa-fw" aria-hidden="true"></i>{{ attach | attachment_link }}
                          </td>
                          <td align="center"><input type="checkbox" name="attach-{{ attach.id }}-DELETE"
                                                    id="attach-{{ attach.id }}-DELETE" class="attach-delete"
                                                    value="{{ attach.id }}"></td>
                        </tr>
                      {% endfor %}
                    {% endif %}
                    </tbody>
                    <tfoot id="se-attachment-names"></tfoot>
                  </table>
                </div>
              </div>
            </div>
            <div class="box-footer">

              {% if perms.attachments.add_attachment %}
                <div class="form-group{% if form.se_attachments.errors %} has-error{% endif %}">
                  {% for error in form.se_attachments.errors %}
                    <div class="col-sm-12 help-block text-center">{{ error }}</div>
                  {% endfor %}
                </div>
                <label class="qa-input btn btn-default btn-sm btn-flat pull-right"
                       title="{% trans "Click to add attachments. (Hold Ctrl or Cmd in the dialog to include multiple attachments)" %}">
                  {% trans "Browse" %} {{ form.se_attachments }}
                </label>
              {% endif %}
            </div>
          </div>
        </div>

        {% if perms.parts.add_partused %}
          <div class="col-md-8">
            <div class="box">
              <div class="box-header">
                <h3 class="box-title">
                  <i class="fa fa-cog fa-fw" aria-hidden="true"></i>
                  {% trans "Parts Used" %}
                </h3>
              </div>
              <div class="box-body">
                <div class="row">
                  <div class="col-md-12">
                    <table class="table table-striped table-hover table-condensed">

                      <thead>
                      {{ part_used_formset.management_form }}
                      <tr>
                        <th class="width-500">{% trans "Part" %}</th>
                        <th>{% trans "Quantity" %}</th>
                        <th class="min-width-100">{% trans "From Storage" %}</th>
                        <th>{% trans "Delete" %}</th>
                      </tr>
                      </thead>

                      <tbody id="parts-used-tbody">

                      {% for pu_form in part_used_formset.forms %}

                        <tr id="{{ pu_form.prefix }}">
                          {{ pu_form.id }}
                          <td id="part-{{ pu_form.prefix }}"
                              class="form-group align-top{% if pu_form.part.errors %} has-error{% endif %}"
                              title="{{ pu_form.part.help_text }}">
                            {{ pu_form.part }}
                            {% for e in pu_form.part.errors %}
                              <div class="help-block">{{ e }}</div>
                            {% endfor %}
                          </td>

                          <td id="quantity-{{ pu_form.prefix }}"
                              class="align-top{% if pu_form.quantity.errors %} has-error{% endif %}">
                            {{ pu_form.quantity }}
                            {% for e in pu_form.quantity.errors %}
                              <div class="help-block">{{ e }}</div>
                            {% endfor %}
                          </td>
                          <td id="from_storage-{{ pu_form.prefix }}"
                              class="align-top{% if pu_form.from_storage.errors %} has-error{% endif %}">
                            {{ pu_form.from_storage }}
                            {% for e in pu_form.from_storage.errors %}
                              <div class="help-block">{{ e }}</div>
                            {% endfor %}
                          </td>

                          <td align="center">{% if pu_form.instance.pk %}{{ pu_form.DELETE }}{% endif %}</td>
                        </tr>
                      {% endfor %}

                      </tbody>

                    {% if perms.parts.add_partused %}
                      <tfoot>
                      <tr>
                        <td colspan="4">
                          <div id="add-part" class="btn btn-default btn-flat btn-sm pull-right">{% trans "Add" %}</div>
                        </td>
                      </tr>
                      </tfoot>
                    {% endif %}

                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>
        {% endif %}
      </div>

      <div class="row">
        <div class="col-md-12">

          <button id="save-se" class="btn btn-flat btn-primary service-save pull-right">{% trans "Save" %}</button>
          {% if perms.service_log.delete_serviceevent and form.instance.id %}
            <a href="{% url 'se_delete' pk=form.instance.id %}"
               class="btn btn-flat btn-default service-delete pull-left">{% trans "Delete" %}</a>
          {% endif %}
        </div>
      </div>
    </div>
  </form>

  {% if form.instance.id %}
    <div class="max-width-lg margin-top-30">
      <div class="row">
        <div class="col-md-12">
          <div class="box">
            <div class="box-header">
              <h4 class="box-title">
                {% blocktrans with service_event_id=form.instance.id %}
                  Service Log For Service Event {{ service_event_id }}
                {% endblocktrans %}
              </h4>
            </div>
            <div class="box-body">
              <div class="row">
                <div class="col-md-12">
                  <ul class="timeline timeline-custom">
                    {% for log in service_logs %}
                      {% render_log log user False True %}
                    {% endfor %}
                  </ul>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  {% endif %}

  <div id="tli_initiated_display_template" style="display: none;">
    <div id="tli_initiated_display" class="col-md-12">
      <span class="label-group">__pass-fail__</span>
      <span class="label-group">__utc-rev__</span>
      <div class="btn-group margin-left-5">
        <a id="view-tli-btn"
           class="btn btn-default btn-xs btn-flat"
           href="{% url 'view_test_list_instance' %}__tli-id__"
           title="View test list"
        >View</a>
        <a class="btn btn-default btn-xs btn-flat new-tab-link"
           href="{% url 'view_test_list_instance' %}__tli-id__"
           target="_blank"
           title="New tab: view test list"
        >
          <i class="fa fa-chevron-right" aria-hidden="true"></i>
        </a>
      </div>
      <span class="pull-right">__utc-date__</span>
    </div>
  </div>

  <table style="display: none;">
    <tbody id="empty-hours-form">
    {% with hours_formset.empty_form as h_form %}
      <tr id="hours-__prefix__" class="hours-row">
        {{ h_form.id }}
        <td>{{ h_form.user_or_thirdparty }}</td>
        <td>{{ h_form.time }}</td>
        <td></td>
      </tr>
    {% endwith %}
    </tbody>
  </table>

  <table style="display: none;">
    <tbody id="empty-rtsqa-form">
    {% with rtsqa_formset.empty_form as f_form %}
      <tr id="rtsqa-__prefix__" class="rtsqa-row">
        {{ f_form.id }}
        {{ f_form.test_list_instance }}
        {{ f_form.all_reviewed }}
        <td class="form-group">{{ f_form.unit_test_collection }}</td>
        <td id="work-completed-rtsqa-__prefix__"></td>
        <td id="pass-fail-rtsqa-__prefix__"></td>
        <td id="review-rtsqa-__prefix__"></td>
        <td id="utc-actions-rtsqa-__prefix__"></td>
        <td></td>
      </tr>
    {% endwith %}
    </tbody>
  </table>

  <table style="display: none;">
    <tbody id="empty-parts-form">
    {% with part_used_formset.empty_form as pu_form %}
      <tr id="parts-__prefix__">
        {{ pu_form.id }}
        <td class="form-group align-top" title="{{ pu_form.part.help_text }}">{{ pu_form.part }}</td>
        <td class="form-group align-top">{{ pu_form.quantity }}</td>
        <td class="form-group align-top">{{ pu_form.from_storage }}</td>
        <td></td>
      </tr>
    {% endwith %}
    </tbody>
  </table>

  <div id="utc-actions-template" style="display: none;">
    <div class="__prefix__-hider" style="display: none;">
      {% if perms.qa.add_testlistinstance %}

        <a id="select-tli-__prefix__"
           title="{% trans "Click to choose the performed return to service test list instance" %}"
           class="btn btn-default btn-xs btn-flat select-tli new-tab-link"
           data-link="{% url 'tli_select' %}/__utc-id__/__prefix__/"
        >
          Performed
          <i class="fa fa-chevron-right margin-left-5" aria-hidden="true"></i>
        </a>
      {% endif %}
      {% if perms.qa.can_review %}
        <div id="__prefix__-review-btn" class="btn-group review-btn __prefix__-hider" style="display: none;">
          <a id="review-tli-__prefix__"
             class="btn btn-default btn-xs btn-flat review-tli new-tab-link"
             data-link="{% url 'review_test_list_instance' %}__prefix__/__tli-id__/"
             title="New tab: click to review this test list"
          >
          {% trans "Review" %}
            <i class="fa fa-chevron-right margin-left-5" aria-hidden="true"></i>
          </a>
        </div>
      {% endif %}
    </div>
  </div>

  <script id="attach-template" type="text/template">
    <div class="col-sm-6">
      <div class="row">
        <div class="col-sm-6">
          <a target="_blank" href="<%= a.url %>">
            <img class="img-responsive" src="<%= a.url %>" alt="<%= a.name %>"/>
          </a>
        </div>
        <div class="col-sm-6">
          <dl>
            <dt>{% trans "File" %}</dt>
            <dd>
              <a target="_blank" href="<%= a.url %>"><%= a.name %></a>
            </dd>

            <dt>{% trans "Size" %}</dt>
            <dd><%= a.size %></dd>
          </dl>
        </div>
      </div>
    </div>
  </script>

  <div class="modal large fade" id="template-modal" tabindex="-1" role="dialog" aria-labelledby="template-modal-label"
       aria-hidden="true">
    <div class="modal-dialog modal-large" role="document">
      <div class="modal-content">

        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">{% trans "Create Template" %}</h4>
        </div>

        <div class="modal-body">

          <form id="template_form" method="post" class="form-horizontal" novalidate>

            <div class="form-group has-success">
              <div id="template-form-success" class="col-sm-offset-4 col-sm-8">
              </div>
            </div>

            {% csrf_token %}
            {% include '_form_horizontal.html' with form=template_form %}
          </form>

        </div>

        <div class="modal-footer">
          <div class="row">
            <div class="col-sm-12">
              <div id="cancel_template" class="btn btn-flat btn-default pull-left" data-dismiss="modal"
                                                                                   data-target="#cancel-modal">
                {% trans "Cancel" %}
              </div>
              <div id="create_template" class="btn btn-flat btn-primary">{% trans "Create" %}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

{% endblock body %}
